<?php

class TestController extends Controller
{
	public function actionIndex(){
		var_dump(Yii::app()->db);
	}
	
	/*
	 * session使用
	*/
	public function actionS1(){
	    //设置session,通过session组件来设置
	    Yii::app()->session['username'] = "zhangsan";
	    Yii::app()->session['useraddr'] = "beijing";
	    echo "make session success";
	}
	
	public function actionS2(){
	    //使用session
	    echo Yii::app()->session['username'],"<br />";
	    echo Yii::app()->session['useraddr'],"<br />";
	    echo "use session success";
	}
	
	public function actionS3(){
	    //删除一个session
	    //unset(Yii::app()->session['useraddr']);
	
	    //删除全部session
	    Yii::app()->session->clear();  //删除session变量
	    Yii::app()->session->destroy(); //删除服务器的session信息
	}
	
	/*
	 * cookie在Yii框架使用
	*/
	public function actionC1(){
	    //设置cookie
	    $ck = new CHttpCookie('hobby','football,basketball');
	    $ck -> expire = time()+3600;
	    //把$ck对象放入cookie组件里边
	    Yii::app()->request->cookies['hobby'] = $ck;
	
	    $ck2 = new CHttpCookie('sex','man');
	    $ck2 -> expire = time()+3600;
	    //把$ck对象放入cookie组件里边
	    Yii::app()->request->cookies['sex'] = $ck2;
	
	    echo "cookie make success";
	}
	public function actionC2(){
	    //访问cookie
	    echo Yii::app()->request->cookies['hobby'],"<br />";
	    echo Yii::app()->request->cookies['sex'];
	}
	public function actionC3(){
	    //删除cookie
	    unset(Yii::app()->request->cookies['sex']);
	}
	
	public function actionPath(){
	    //输出路径别名信息/yii就是框架直接可以操作使用的类
	    //Yii::app()　是一个实例，是在当前框架里边唯一可以直接使用的实例对象
	    //echo Yii::getPathOfAlias('system');  //D:\www\0507\framework
	    //echo Yii::getPathOfAlias('system.web');  //D:\www\0507\framework\web
	    //echo Yii::getPathOfAlias('application');  //D:\www\0507\shop\protected
	    //echo Yii::getPathOfAlias('zii');  //D:\www\0507\framework\zii
	    echo Yii::getPathOfAlias('webroot');  //D:/www/0507/shop
	
	}
}